<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.Date"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>IPL 2011</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<link rel="shortcut icon" href="images/cric_fav.ico" />
<script type="text/javascript">
function validate(){
	if (document.playerStats.winner.value =='--')
	{
		alert("Please select Match-1 Winner");
		return false;
    }
    else if (document.playerStats.manOfMatch.value =='') 
    {
        alert("Please select Team of Man of the Match");
	    return false;
    }
    else if (document.playerStats.sixesWinner.value =='--') 
    {
        alert("Please select Team of Man of the Match");
	    return false;
    }else if (document.playerStats.sixes.value =='--') 
    {
        alert("Please select Team of Man of the Match");
	    return false;
    }else{
    	return true;
    }
    
}

</script>
</head>
<body>
<%@ include file="global.jsp" %>
<form action="/IPL/processPlayerStats.jsp"  name="playerStats" method = "post">
	<div id="container">
		<!-- Start of Page Menu -->
		<div id="page_menu">
			<ul>
			<li><a href="/IPL/Home.jsp">TEAMS</a></li>
			<li><a href="/IPL/Schedule.htm">SCHEDULE</a></li>
			<li><a href="/IPL/MatchSelect.jsp">TODAYS QUIZ</a></li>
			<li><a href="/IPL/Points.jsp">SCORES</a></li>
			<li><a href="/IPL/Choice.jsp">CHOICE</a></li>
			<li class="last"><a href="/IPL/Feedback.jsp">DISHUM DISHUM</a></li>	
			</ul>
		</div>
			<!-- End of Page Menu -->
		<div id="main_content">
			<%
			try{
				List players = new ArrayList();
				String parameter = request.getParameter("matchId");
				String matchId = parameter.substring(0,parameter.indexOf("*"));
				System.out.println("matchId:::"+matchId);
			    String teams = matchId.substring(matchId.indexOf("@")+1,matchId.length());
			    System.out.println("teams:::"+teams);
			    String team1 = teams.substring(0,teams.lastIndexOf("|"));
			    System.out.println(teams.lastIndexOf("|"));
			    String team2 = teams.substring(teams.lastIndexOf("|")+1,teams.length());
			    System.out.println(team1);
			    System.out.println(team2);
			    Class.forName(db_driver);
    			Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
		        Statement stmt = conn.createStatement();
				ResultSet rset = stmt.executeQuery("select distinct(mom) from mccanswers where matchId='"+matchId+"'");
		        while (rset.next()){
		        	
		        	if(!players.contains(rset.getString(1))){
		        		players.add(rset.getString(1));
		        	}
		        }
		        rset = stmt.executeQuery("select distinct(player1) from mccanswers where matchId='"+matchId+"'");
		        while (rset.next()){
		        	
		        	if(!players.contains(rset.getString(1))){
		        		players.add(rset.getString(1));
		        	}
		        }
		        rset = stmt.executeQuery("select distinct(player2) from mccanswers where matchId='"+matchId+"'");
		        while (rset.next()){
		        	
		        	if(!players.contains(rset.getString(1))){
		        		players.add(rset.getString(1));
		        	}
		        }
		        session.setAttribute("players",null);
				session.setAttribute("players",players);
				session.setAttribute("matchId",null);
				session.setAttribute("matchId",matchId);
		        System.out.println("SIZE:"+players.size());
		        stmt.close();
		        conn.close();
		        
		        %>
		        <br>
		        <h2><%=matchId%></h2>
		        <br>
		        <table  id="runswickets" width="100%" style="tableClass" border="1" cellspacing="1" cellpadding="1">
			        <tbody>
				        <tr>
				        	<td>Winner:</td>
				        	<td>
				        		<select name="winner">
				        			<option style="background-color:black;color:#33FFFF" value="--">--Select Winner--</option>
									<option style="background-color:black;color:#33FFFF" value="<%=team1%>"><%=team1%></option>
									<option style="background-color:black;color:#33FFFF" value="<%=team2%>"><%=team2%></option>
				        	    </select>
				        	</td>
				        </tr>
				        <tr>
				        	<td>MOM:</td>
				        	<td><input type="text" name="manOfMatch"/></td>
				        </tr>
				        <tr>
				        	<td>Winner:</td>
				        	<td>
				        		<select name="sixesWinner">
				        			<option style="background-color:black;color:#33FFFF" value="--">--Select Winner--</option>
									<option style="background-color:black;color:#33FFFF" value="<%=team1%>"><%=team1%></option>
									<option style="background-color:black;color:#33FFFF" value="<%=team2%>"><%=team2%></option>
				        	    </select>
				        	</td>
				        </tr>
				        <tr>
				        	<td>Sixes:</td>
				        	<td>
				        		<select style="background-color:black;color:white" name="sixes">
									<option style="background-color:black;color:#33FFFF" value="-1">--No.of Sixes--</option>
									<option style="background-color:black;color:#33FFFF" value="0-2">-- 0 to 2 --</option>
									<option style="background-color:black;color:#33FFFF" value="3-6">-- 3 to 6 --</option>
									<option style="background-color:black;color:#33FFFF" value="7-9">-- 7 to 9 --</option>
									<option style="background-color:black;color:#33FFFF" value="10-12">-- 10 to 12 --</option>
									<option style="background-color:black;color:#33FFFF" value="13-15">-- 13 to 15 --</option>
									<option style="background-color:black;color:#33FFFF" value="16+">-- 16 & above --</option>
							  	</select>
				        	</td>
				        </tr>
				    </tbody>
			    </table>
		        <br>
	        	<br>
	        	<center>
	        		<table>
	        			<tr>
				        	<td>
				        		<input type="submit"  value="Update The Stats" size="7" onClick="javascript:validate();"/>
				        	</td>
			        	</tr>
	        		</table>
	        	</center>
	        	<%
			}
	  		catch ( Exception e1){
				e1.printStackTrace();
			} 
			finally{
			}
				
			%>
		</div>
	</div>
	
</form>
</body>
</html>